﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Migraine.BLL;

namespace Migraine.MyUC.UCHienThi
{
    public partial class ucThemLuat : UserControl
    {
        LuatBUO lBUO = new LuatBUO();
        BenhBUO bBUO = new BenhBUO();
        public ucThemLuat()
        {
            InitializeComponent();

            int numberOfBenh = bBUO.GetAll().Count();
            string[] list = new string[numberOfBenh];
            for (int i = 0; i < numberOfBenh; i++)
            {
                list[i] = bBUO.GetAll()[i].TenBenh;
            }
            comboBox1.DataSource = list;

            loadData();
        }

        private void loadData()
        {
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = lBUO.GetAll();
        }

        void themLuat()
        {
            tbl_Luat luat = new tbl_Luat();

            luat.idLuat = "A";
            luat.idBenh = bBUO.getIDFromTenBenh(comboBox1.Text);
            if (lBUO.Insert(luat))
            {
                //Thêm luật thành công
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            themLuat();
            Form t = this.ParentForm;
            ucThemTC_Luat themtcl = new ucThemTC_Luat();
            ControlAcess.ShowConTrol(t, themtcl, "gbHienthi");
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
            tbl_Luat luat = lBUO.GetSingle(id);
            comboBox1.Text = bBUO.getTenBenhFromID(luat.idBenh); 
        }
    }
}
